<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<jsp:include page="js/jsAll.html"></jsp:include>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>选课管理</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<security:authorize ifNotGranted="ROLE_CONNECT">
	<s:if test="#session.USER_NAME==null">
		<script type="text/javascript" src="pagejs/login.js"></script>
	</s:if>
</security:authorize>
<script type="text/javascript">
	Ext.onReady(function() {
		Ext.QuickTips.init();
		var store = new Ext.data.JsonStore({
			root : 'root',
			url : 'getCurriculum.action',
			fields : [ 'id', 'date', 'ampm', 'name', 'teacher']
		});
		var selectStore = new Ext.data.JsonStore({
			root : 'root',
			url : 'getCurriculumListByUserName.action',
			fields : ['id','curriculumId']
		});
		selectStore.load();
		store.load();
		function renderToAmPm(value, p, record){
	        if(value=="am"||value=="AM")
	        {
	        	return "上午";	
	        }
	        else
	        {
	        	return "下午";	
	        }
		}
		var grid = new Ext.grid.GridPanel({
			store : store,
			sm : new Ext.grid.RowSelectionModel({
				singleSelect : true
			}),
			region: 'west',
			columns : [{
				id : 'id',
				header : "课程id",
				width : 80,
				sortable : true,
				dataIndex : 'id'
			},
			{
				header : "日期",
				width : 85,
				sortable : true,
				renderer : Ext.util.Format.dateRenderer('Y-m-d'),
				dataIndex : 'date'
			},
			{
				header : "时间",
				width : 75,
				sortable : true,
				dataIndex : 'ampm',
				renderer :renderToAmPm
			}, {
				header : "课程名",
				width : 200,
				sortable : true,
				dataIndex : 'name'
			}, {
				header : "老师",
				width : 75,
				sortable : true,
				dataIndex : 'teacher'
			}
			],
			stripeRows : true,
			height : 300,
			width:510,
			title : '课程列表',
			tbar : [ {
				text : '添加课程',
				id:'class_add',
				handler : function() {
					var records = grid.getSelectionModel().getSelections();
					var id=records[0].get('id');
					Ext.Ajax.request({
						method : 'POST',
						url:'addCurriculumList.action',
						params:{'cuId':id},
						callback:function(optioons,success,response){
							if(success)
							{
								Ext.MessageBox.alert('提示','添加成功');
								selectStore.load();
							}
							else
							{
								Ext.MessageBox.alert('提示','添加失败');
							}
						}
					});
				}
			}
			]
			
		});
 
		var selectedGrid = new Ext.grid.GridPanel({
			store : selectStore,
			region: 'center',
			sm : new Ext.grid.RowSelectionModel({
				singleSelect : true
			}),
			columns : [{
				id : 'id',
				header : "选课ID",
				width : 40,
				sortable : true,
				dataIndex : 'id'
			},{
				id : 'curriculumId',
				header : "课程ID",
				width : 140,
				sortable : true,
				dataIndex : 'curriculumId'
			}
			],
			stripeRows : true,
			height : 300,
			width:510,
			title : '选课列表',
			tbar : [ {
				text : '删除课程',
				id:'class_del',
				handler : function() {
					var records = selectedGrid.getSelectionModel().getSelections();
					var id=records[0].get('id');
					Ext.Ajax.request({
						method : 'POST',
						url:'removeCurriculumListById.action',
						params:{'cuId':id},
						callback:function(optioons,success,response){
							if(success)
							{
								Ext.MessageBox.alert('提示','删除成功');
								selectStore.load();
							}
							else
							{
								Ext.MessageBox.alert('提示','删除失败');
							}
						}
					});
				}
			}
			]
		});
		
		var curriculumPanel = new Ext.Panel({
            layout: 'border',
            height : 300,
            items: [grid, selectedGrid]
		});
		curriculumPanel.render('curriculum');
		<s:if test="#session.USER_NAME==null">
			Ext.getCmp('class_del').setVisible(false);
			Ext.getCmp('class_add').setVisible(false);
		</s:if>
	});
</script>
<body  class="mt-main-index">
	<div id="login-win" class="x-hidden"></div>
	<div id="register-win" class="x-hidden"></div>
<div id="top"><a href="chooseLocales.action?lanague=zh">中文</a>/<a href="chooseLocales.action?lanague=en" >English</a></div>
<div id="container">
<div id="header">
<div id="header-inner">
<div id="header-content">
<h1 id="header-name"></h1>
</div> <!-- end header-content --> 
</div> <!-- end header-inner --> 
</div> <!-- end header --> 
 
 <div id="main-navigation">
     <ul>
     <s:i18n name="globalMessage">
    	<li><a href="index.jsp"><s:text name="menu.home" /></a></li>
     	<li><a href="#"><s:text name="menu.children"/></a>
     	   	<ul class='nav-level-2'>
	     		<li><a href="children.jsp"><s:text name="menu.childrensworkdisplayed" /></a></li>
	     		<li><a href="class.jsp"><s:text name="menu.elective" /></a></li>
     		</ul>
     	</li>
     	<li><a href="chat.jsp"><s:text name="menu.chat" /></a></li> 
       	<li><a href="map.jsp"><s:text name="menu.map" /></a></li>
       	<li><a href="music.jsp"><s:text name="menu.mp3dowload" /></a></li>
       </s:i18n>
      </ul>
    </div><!--end main-navigation --> 
	<div id="content">
   	<div id="curriculum">
   	</div>
    </div><!--end content-->
	<div id="footer">
    
            朝阳教堂
    
    
    </div>
</div> <!-- end container --> 
</html>